'''
loaders
Author: Alex Foran
'''

import pygame

'''
Loads a non-alpha image, returning a pygame.image instance. Returns None if an error occurs.

Params:
fullname - The path to the image.
colorkey - The color to treat as transparent. If None is specified, no colorkey will be used. If -1 is specified, the function will attempt to determine it automatically.
'''
def load_image(fullname,colorkey=None):
	try:
		image = pygame.image.load(fullname)
	except pygame.error, message:
		print 'Cannot load image:', fullname
		return None
	image = image.convert()
	if colorkey is not None:
		#load from upper left corner
		if colorkey is -1:
			colorkey = image.get_at((0,0))
		image.set_colorkey(colorkey, pygame.RLEACCEL)
	return image

'''
Loads an image, maintaining alpha transparency. Drawing these images is significantly slower.

Params:
fullname: The path to the image.
'''
def load_image_alpha(fullname):
	try:
		image = pygame.image.load(fullname)
	except pygame.error, message:
		print 'Cannot load image:', fullname
		return None
	image = image.convert_alpha()
	return image
	
'''
Loads a sound, returning a pygame.sound object.

Params:
fullname - The path to the file.
'''
def load_sound(fullname):
	try:
		sound = pygame.mixer.Sound(fullname)
	except pygame.error, message:
		print 'Cannot load sound:', fullname
		sound=None
	return sound